use std::io::prelude::*; //导入IO常用trait

const BYTES_PER_LINE: usize = 16;
//原始数据，视为字节数据(&[u8])而不是文本数据(&str)
const INPUT: &'static [u8] = br#" 
fn main(){
    println!("Hello, world!");
}
"#;

fn main() -> std::io::Result<()> {
    let mut buffer: Vec<u8> = vec![]; //创建内部缓冲区
    INPUT.read_to_end(&mut buffer)?; //读取信息插入内部缓冲区

    let mut position_in_input = 0;
    for line in buffer.chunks(BYTES_PER_LINE) {
        print!("[0x{:08x}] ", position_in_input); //输出当前位置信息，最多8位，不够补0
        for byte in line {
            print!("{:02x} ", byte);
        }
        println!(); //输出换行符
        position_in_input += BYTES_PER_LINE;
    }
    Ok(())
}
